// pages/load/load.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName: '',
    passWord: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight
        })
      },
    })
    wx.login({
      success: function (res) {
        wx.request({
          url: app.globalData._url + 'MenuAPI/WeChatLogin/GetSessionBoss',
          data: { code: res.code, nickName: '', appid: app.globalData.appid, secret: app.globalData.secret, isDiancanFlow: 1, shopId: '', session: '' },
          method: 'POST',
          success: function (res) {
            console.log(res)
            app.globalData.openId = res.data.openid
          }
        })
        console.log(res)
      }
    })
    wx.setNavigationBarTitle({
      title: '超急送',
    })
  },
  toindex: function () {

    wx.request({
      url: app.globalData._url + 'MenuAPI/Login/Login',
      data: { username: this.data.userName, password: this.data.passWord },
      method: 'post',
      success: function (res) {
        console.log(res)
        if (res.data.responseData == 200) {
          app.globalData.shopId = res.data.data.shopId
          app.globalData.shopName = res.data.data.shopName
          wx.showLoading({
            title: '登陆成功',
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 1000)
          wx.navigateTo({
            url: '../index/index',
          })

        } else {
          wx.showModal({
            title: '登陆失败',
            content: res.data.msg,
          })
        }
      }
    })

  },
  admin: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  psd: function (e) {
    this.setData({
      passWord: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})